#include <LPC23xx.H>               // LPC213x definitions 


/*
 * Software Interrupt Function accept parameters and run in
 * Supervisor Mode (Interrupt protected)
 */

int __swi(0) add (int i1, int i2);
int __SWI_0      (int i1, int i2) {
  return (i1 + i2);
}

int __swi(1) mul4(int i);
int __SWI_1      (int i) {
  return (i << 2);
}

int __swi(2) div (int i1, int i2);
int __SWI_2      (int i1, int i2) {
  return (i1 / i2);
}

int __swi(3) mod (int i1, int i2);
int __SWI_3      (int i1, int i2) {
  return (i1 % i2);
}


int res;


/*
 * Test Function in Thumb Mode
 */

#pragma thumb

void test_t (void) {
  res  = div (res, 10);            // Call SWI Functions
  res  = mod (res,  3);
}


/*
 * Test Function in ARM Mode
 */

#pragma arm

void test_a (void) {
  res  = add (74,  27);            // Call SWI Functions
  res += mul4(res);
}


/*
 * Sample 'main' Function
 */

void main (void) {

  test_a();
  test_t();

	while (1);                       // Endless Loop
}
